package com.objetdirect.gwt.umldrawer.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;

public class HeaderButtons {

	private HorizontalPanel buttons = new HorizontalPanel() ;
	private Image home = new Image("images/home.png");
	private Image signIn = new Image("images/signIn.png") ;
	private Image signUp = new Image("images/signUp.png") ;
	private Image aboutUs = new Image("images/aboutUs.png") ;
	private Image tutorials = new Image("images/tutorials.png") ;
	private Image samples = new Image("images/samples.png") ;
	private Image signOut = new Image("images/signOut.png");
	
	public HorizontalPanel getHeaderButtons() {

		if (History.getToken().equals("TermsOfUse")) {
			buttons.setStyleName("TermsOfUsePageButtons");
		}
		else
			buttons.setStyleName("homePageButtons");
		
		
		buttons.add(home);
		if (History.getToken().equals("Account")) {
			buttons.setStyleName("AccountButtons");
			buttons.add(signOut);
		}
		else {
			buttons.add(signIn);
			buttons.add(signUp);
		}
		buttons.add(tutorials);
		buttons.add(samples);
		buttons.add(aboutUs);
		
		home.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				History.newItem("Home");
			}
		});
		
		home.addMouseOverHandler(new MouseOverHandler() {
			@Override
			public void onMouseOver(MouseOverEvent event) {
				home.setUrl("images/home_.png");
			}
		});
		
		home.addMouseOutHandler(new MouseOutHandler() {
			@Override
			public void onMouseOut(MouseOutEvent event) {
				home.setUrl("images/home.png");
			}
		});
		
		signIn.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				History.newItem("SignIn");
			}
		});
		
		signIn.addMouseOverHandler(new MouseOverHandler() {
			@Override
			public void onMouseOver(MouseOverEvent event) {
				signIn.setUrl("images/signIn_.png");
			}
		});
		
		signIn.addMouseOutHandler(new MouseOutHandler() {
			@Override
			public void onMouseOut(MouseOutEvent event) {
				signIn.setUrl("images/signIn.png");
			}
		});
		
		signUp.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				History.newItem("SignUp");
			}
		});
		
		signUp.addMouseOverHandler(new MouseOverHandler() {
			@Override
			public void onMouseOver(MouseOverEvent event) {
				signUp.setUrl("images/signUp_.png");
			}
		});
		
		signUp.addMouseOutHandler(new MouseOutHandler() {
			@Override
			public void onMouseOut(MouseOutEvent event) {
				signUp.setUrl("images/signUp.png");
			}
		});
		
		tutorials.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				History.newItem("Tutorials");
			}
		});
		
		tutorials.addMouseOverHandler(new MouseOverHandler() {
			@Override
			public void onMouseOver(MouseOverEvent event) {
				tutorials.setUrl("images/tutorials_.png");
			}
		});
		
		tutorials.addMouseOutHandler(new MouseOutHandler() {
			@Override
			public void onMouseOut(MouseOutEvent event) {
				tutorials.setUrl("images/tutorials.png");
			}
		});
		
		samples.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				History.newItem("Samples");
			}
		});
		
		samples.addMouseOverHandler(new MouseOverHandler() {
			@Override
			public void onMouseOver(MouseOverEvent event) {
				samples.setUrl("images/samples_.png");
			}
		});
		
		samples.addMouseOutHandler(new MouseOutHandler() {
			@Override
			public void onMouseOut(MouseOutEvent event) {
				samples.setUrl("images/samples.png");
			}
		});
		
		aboutUs.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				History.newItem("AboutUs");
			}
		});
		
		aboutUs.addMouseOverHandler(new MouseOverHandler() {
			@Override
			public void onMouseOver(MouseOverEvent event) {
				aboutUs.setUrl("images/aboutUs_.png");
			}
		});
		
		aboutUs.addMouseOutHandler(new MouseOutHandler() {
			@Override
			public void onMouseOut(MouseOutEvent event) {
				aboutUs.setUrl("images/aboutUs.png");
			}
		});
		
		signOut.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				History.newItem("Home");
			}
		});
		
		signOut.addMouseOverHandler(new MouseOverHandler() {
			@Override
			public void onMouseOver(MouseOverEvent event) {
				signOut.setUrl("images/signOut_.png");
			}
		});
		
		signOut.addMouseOutHandler(new MouseOutHandler() {
			@Override
			public void onMouseOut(MouseOutEvent event) {
				signOut.setUrl("images/signOut.png");
			}
		});
		
		return buttons ;
	}
}